package com.zenithmind.user.utils;

import com.zenithmind.user.security.PasswordEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 密码工具类（兼容性保留）
 * 遵循依赖倒置原则：委托给PasswordEncoder接口实现
 *
 * @deprecated 建议直接使用 {@link PasswordEncoder} 接口
 */
@Deprecated
@Component
public class PasswordUtils {

    private static PasswordEncoder passwordEncoder;

    @Autowired
    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
        PasswordUtils.passwordEncoder = passwordEncoder;
    }

    /**
     * 对给定的密码进行加密处理
     *
     * @deprecated 使用 {@link PasswordEncoder#encode(String)} 替代
     */
    @Deprecated
    public static String encryption(String password) {
        if (passwordEncoder == null) {
            throw new IllegalStateException("PasswordEncoder未初始化");
        }
        return passwordEncoder.encode(password);
    }

    /**
     * 比较用户输入的密码与存储在数据库中经过加密的密码是否匹配
     *
     * @deprecated 使用 {@link PasswordEncoder#matches(String, String)} 替代
     */
    @Deprecated
    public static boolean compare(String password, String encodedPassword) {
        if (passwordEncoder == null) {
            throw new IllegalStateException("PasswordEncoder未初始化");
        }
        return passwordEncoder.matches(password, encodedPassword);
    }
}